function loadLocations(id) {
	$.ajax({
		type : 'POST',
		dataType : 'json',
		data : {
			id_reg : id
		},
		url : 'index.php?r=data/getLocations',
		success : function(data) {
			document.getElementById('r_' + id).setAttribute('src',
					'images/minus.png');
			region = 'region_' + id;
			
			var newElement = document.createElement('div');
				newElement.id = 'div_' + region;
				newElement.style = 'display: none';
				
			document.getElementById(region).appendChild(newElement);
			for (i = 0; i < data.length; i++) {
				var newElement = document.createElement('span');
					newElement.textContent = data[i]['title'];
					newElement.id = 'location_' + data[i]['id'];
					newElement.className = 'location_view';
				
				var newElement2 = document.createElement('a');
					newElement2.setAttribute('href', '#');
					newElement2.setAttribute('onclick', 'calcChartsData('
							+ data[i]['id']+','+ data[i]['title'] +');');
					newElement2.className = 'zoom';
					newElement2.textContent = 'pokaż miejsce';
				
				document.getElementById('div_' + region)
						.appendChild(newElement);
				
				document.getElementById('div_' + region).appendChild(
						newElement2);
				
				document.getElementById('div_' + region).appendChild(
						document.createElement('br'));
				
				$('#div_' + region).slideDown('slow');
			}
			document.getElementById('r_' + id).onclick = function() {
				$('#div_region_' + id).slideUp('slow', function() {
					removeRegionChilds(id);
				});
			};
		},
		error : function(data, textStatus, jqXHR) {
			alert('294');
		},
		dataType : 'json'
	});
}


function removeRegionChilds(number) {
	var cell = document.getElementById('region_' + number);
	if (cell.hasChildNodes())
		while (cell.childNodes.length >= 2) {
			cell.removeChild(cell.lastChild);
		}
	document.getElementById('r_' + number).onclick = function() {
		loadLocations(number);
	};
	document.getElementById('r_' + number).setAttribute('src',
			'images/plus.png');
}